# rocketmq 队列配置
mq_config = {
    # 'prod': {
    #     'server_addr': 'http://XXX.cn-beijing.mq-internal.aliyuncs.com:8080',
    #     'group_id': 'XXX',
    #     'topic': 'XXX',
    #     'appkey': 'XXX',
    #     'secretKey': 'XXX',
    #     'callback_func': 'utils.mq_utils.used_tag_update.callback_func'
    # },
}

# es 搜索引擎配置
es_config = {
    'log': {
        'es_host': "http://es-cn-XXX.elasticsearch.aliyuncs.com:9200/data_center_log.*",
        'es_user': 'elastic',
        'es_passwd': 'XXX'
    },
}

# mysql 数据库配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '172.20.0.XXX',
        'PORT': 3306,
        'USER': 'XXX',
        'PASSWORD': 'XXX',
        'NAME': 'qk_aic',
        'CONN_MAX_AGE': 10
    },
    'bid': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '172.20.0.XXX',
        'PORT': 3306,
        'USER': 'XXX',
        'PASSWORD': 'XXX',
        'NAME': 'qk_bid',
        'CONN_MAX_AGE': 10
    },
}


# 配置多数据库路由规则，实现读写分离等操作
class MasterSlaveRouter(object):
    def db_for_read(self, model, **hints):
        if model._meta.app_label in ['bid', ]:
            return 'bid'
        return 'default'

    def db_for_write(self, model, **hints):
        if model._meta.app_label in ['bid', ]:
            return 'bid'
        return 'default'

    def allow_relation(self, obj1, obj2, **hints):
        return True

    def allow_syncdb(self, db, model):
        if model._meta.app_label in ['bid', ] and db in ['bid', ]:
            return 'bid'
        return 'default'


DATABASE_ROUTERS = ['mainsys.config.MasterSlaveRouter']

# redis 缓存配置
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://redis-XXX.redis.rds.aliyuncs.com:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}
